package com.sitech.portal.system.dao.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sitech.ibnms.core.BaseIbnmsDao;
import com.sitech.ibnms.core.IPage;
import com.sitech.ibnms.core.PageForm;
import com.sitech.portal.system.dao.ISysLogDao;

public class SysLogDaoImpl extends BaseIbnmsDao implements ISysLogDao {

	public void add(Map map) {
		this.insert("insertForTB_SYS_LOG", map);
	}

	public IPage findListByPK(String userId,PageForm pageForm) {
        HashMap map = new HashMap();
        map.put("userId",userId);
		return this.findPage("findIdForTB_SYS_LOG", map,pageForm);
	}
	
	public IPage findLogByPK(String id,PageForm pageForm) {
		String mySql = "";
		mySql = "  select t.*, c.cn_name, c.title_expression from TB_SYS_LOGGING t, tb_sys_logging_cfg c where t.id = '"+id+"' and t.operate_class = c.operate_class and t.operate_method = c.operate_method and c.enable='1' ";
		return this.findPage("findLogByPK", mySql,pageForm);
	}

	public List findUserList(String dept_id) {
		String sql = "";
		sql = "select login_id,name  from tb_sys_loginmsg where dept_id ='"
				+ dept_id + "'";

		return this.query("findIdForTB_SYS_LOGING", sql);

	}

	public List getAllModuleForLogin(String loginId, String pre_super,
			int pre_super_len) {
            String mysql = "SELECT DISTINCT a.module_id, b.module_name, b.module_path, b.module_target"
                    + " FROM tb_sys_role_module a, tb_sys_module b"
                    + " WHERE role_id IN (SELECT role_id FROM tb_sys_user_role WHERE login_id = '"
                    + loginId
                    + "') AND a.module_id = b.module_id and b.module_enable='1'"
                    + " and b.page_element is null "
                    + " AND a.module_id LIKE '" + pre_super + "%'";
//		if (pre_super != null && pre_super.length() == 2) {
//			mysql += " AND instr(a.module_id,'00') in (4,5,6,7)";
//		} else if (pre_super != null && pre_super.length() == 4) {
//			mysql += " AND instr(a.module_id,'00') in (6,7)";
//		}
            mysql += " AND (instr(a.module_id,'00') between length('" + pre_super + "')+2 and length('" + pre_super + "')+3)";
            mysql += " order by module_id";
            return this.query("getAllModuleForLogin", mysql);

	}

	public HashMap getModuleInfoByPk(String module_id) {
		return (HashMap) this.querySingle("getModuleInfoByPk",
					module_id);
	}
	
	public void loggingAdd(Map map) {
		this.insert("insertForTB_SYS_LOGGING", map);
	}
	
	public HashMap getTB_SYS_LOGGING_CONFIGByAOP(String AOP_CLASS,String AOP_METHOD){
		Map map =  new HashMap();
		map.put("AOP_CLASS", AOP_CLASS);
		map.put("AOP_METHOD", AOP_METHOD);
		return (HashMap) this.querySingle("getTB_SYS_LOGGING_CONFIGByAOP",
				map);
	}
	
	public List getTbinfoByIds(Map map){
		return this.query("getTbinfoByIds", map);
	}
}
